import request from '@/utils/request'
import type {
  ProductInfo,
  ProductQueryParams,
  ProductListResponse,
  ProductDetailResponse,
  ProductOperationResponse,
  ProductFormData
} from './types'

// 获取产品列表
export function getProductList(params: ProductQueryParams): Promise<ProductListResponse> {
  return request({
    url: '/protocol/product/list',
    method: 'get',
    params
  })
}

// 获取产品详情
export function getProductDetail(productId: string | number): Promise<ProductDetailResponse> {
  return request({
    url: `/protocol/product/${productId}`,
    method: 'get'
  })
}

// 新增产品
export function addProduct(data: ProductFormData): Promise<ProductOperationResponse> {
  return request({
    url: '/protocol/product',
    method: 'post',
    data
  })
}

// 修改产品
export function updateProduct(data: ProductFormData): Promise<ProductOperationResponse> {
  return request({
    url: '/protocol/product',
    method: 'put',
    data
  })
}

// 删除产品
export function deleteProduct(productIds: string): Promise<ProductOperationResponse> {
  return request({
    url: `/protocol/product/${productIds}`,
    method: 'delete'
  })
}

// 导出产品
export function exportProduct(params: ProductQueryParams): Promise<any> {
  return request({
    url: '/protocol/product/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  })
}